var docTypeStore=new Ext.data.JsonStore(
	{data:[{name:'供应商订单',value:'1'},
	{name:'客户订单',value:'2'}],
	fields:['name','value']
});

var payStateStore=new Ext.data.JsonStore({
	data:[{name:'未付款',value:'0',color:'red'},
	{name:'已付款',value:'1',color:'blue'}],
	fields:['name','value','color'],
	autoDestroy :false
});

var deliverGoodsStore=new Ext.data.JsonStore({
	data:[{name:'未发货',value:'0',color:'red'},
	{name:'已发货',value:'1',color:'blue'}],
	fields:['name','value','color']
});

var optStateStore=new Ext.data.JsonStore({
			data:[{name:'未处理',value:'0',color:'orange'},
			{name:'订购成功',value:'1',color:'blue'},
			{name:'订购失败',value:'2',color:'red'}],
			fields:['name','value','color'],
			autoDestroy :false
		})
/**供应商面板*/
function showSupplierWindow(){
	var win=new Ext.Window({
		title:'供应商订单详细',
		modal :'true',
		layout: 'border',
		width:800,
		height:350,
		autoDestroy:true,
		resizable :false,
		showGridData : function (rep){
				var supplierStore = Ext.getCmp('supplierDetailGrid').getStore();
				supplierStore.removeAll();
				var proxyManagerStore=Ext.getCmp('supplier_proxyManager_Grid').getStore();
				proxyManagerStore.removeAll();
				Ext.each(rep.obj.suppOrderDetailBolist, function(data) {
					var rd = Record_create_FromArray(data);
					if(Ext.isEmpty(rd.get('inlayDiamondId')) ||rd.get('inlayDiamondId')<1 ){
						supplierStore.add(rd);
					}else{
						proxyManagerStore.add(rd);
					}
				});
			},
		buttons:[{
			text:'返回',
			handler:function(bt,e){
				var p=bt.ownerCt.ownerCt;
				p.destroy();
			}
		}],
	    items: [{
			region: 'north',
			split: true,
			border: false,
			height: 100,
			collapseMode: 'mini',
			layout: 'column',
			frame: true,
			defaults: {
				anchor: '95%',
				columnWidth: 0.32,
				layout: 'form',
				labelWidth: 65,
				defaults: {
					anchor: '95%',
					editable: false,
					xtype: 'textfield'
					}
				},
				items: [{
					labelWidth: 60,
					items: [{
						fieldLabel: '订单类型',
						disabled : true, 
						name : 'orderType',
						id : 'orderType_id',
						emptyText:'供应商订单'
					},{
						fieldLabel: '下单时间',
						disabled : true,
						name : 'orderDate',
						id : 'orderDate_id'
//						xtype: 'datefield'
					}]
				}, {
					items: [{
						fieldLabel: '订单编号',
						disabled : true,
						name : 'orderNo',
						id: 'orderNo_dl_fl'
					},{
						fieldLabel: '供应商名称',
						name : 'supplierName',
						disabled : true,
						id: 'supplierName_dl_fl2'
					}]
				}, {
					items: [{
						fieldLabel: '单据状态',
						disabled : true,
						name : 'orderStatus',
						id: 'orderStatus_dd_fl'
					},{
						fieldLabel: '经销商名称',
						name : 'userName',
						disabled : true,
						id: 'userName_dd_fl2'
					}]
				}, {
					labelWidth: 60,
					columnWidth:'0.99',
					items: [{
						fieldLabel: '订单备注',
						disabled : true,
						name : 'orderRemark',
						id: 'orderRemark_id'
					}]
				}]
		}, {
	        	region: 'center',
		        split: true,
		        frame: true,
		        border: false,
				xtype:'grid',
				id:'supplierDetailGrid',
				cm: new Ext.grid.ColumnModel({
					  defaultSortable: true,
					  defaultWidth: 85,
					  columns:suppGridColumns
					}),
				store: new Ext.data.JsonStore({
						url:'',
						fields:getFieldsFromColumns(suppGridColumns)
					})
	    	},{
					height:120,
					xtype:'grid',
			     	region: 'south',
			     	id:'supplier_proxyManager_Grid',
			     	collapseMode: 'mini',
			        split: true,
			        store: new Ext.data.JsonStore({
						url:'queryInlayDiamondList.action',
						totalProperty: 'obj.totalSize', 
						successProperty :'success',
						root:'obj.returnBolist',
						messageProperty:'msg',
						fields:getFieldsFromColumns(proxyManager_columns)
			        }),
					cm: new Ext.grid.ColumnModel({
						  defaultSortable: true,
						  defaultWidth: 85,
						  columns:proxyManager_columns
						})
			}]
	})
	win.show();
	return win;
}




var clientWin=null;
/**经销商面板*/
function showDealerWindow(){
	if(clientWin!=null){
		clientWin.show();
		return clientWin;
	}
	//客户订单明细
//var clientGrid_submitData=[];
var clientGridColumns=[NumberColumn_create(),{
    dataIndex: "cliOrdMasterId",
	hidden:true,
	hideable:false
}, {
    dataIndex: "cliOrdrDetailId",
	hidden:true,
	hideable:false
},{
    dataIndex: "suppOrdMasterId",
	hidden:true,
	hideable:false
},{
    header: "商品编号",
    align : 'center',
    width : 80,
    dataIndex: "batch"
},{
    header: "重量",
    align : 'center',
    width : 35,
    dataIndex: "weight"
},{
    header: "颜色",
    align : 'center',
    width : 35,
    dataIndex: "color"
},{
    header: "净度",
    align : 'center',
    width : 35,
    dataIndex: "clarity"
},{
    header: "抛光",
    align : 'center',
    width : 35,
    dataIndex: "polish"
},{
    header: "荧光",
    align : 'center',
    width : 35,
    dataIndex: "fluor"
},{
    header: "形状",
    align : 'center',
    width : 50,
    dataIndex: "shape"
},{
    header: "对称性",
    align : 'center',
    width : 50,
    dataIndex: "symmetry"
},{
    header: "切工",
    align : 'center',
    width : 35,
    dataIndex: "finalCut"
},{
    header: "证书号",
    align : 'center',
    width : 70,
    dataIndex: "reportNo"
},{
    header: "单价",
    align : 'center',
    width : 55,
    dataIndex: "midPrice"
}, {
    header: "数量",
    align : 'center',
    width : 35,
    dataIndex: "amount"
}, {
    header: "供应商",
    align : 'center',
    width: 60,
    dataIndex: "supplierName"
},{
    header: "操作状态",
    align : 'center',
    width : 60,
    dataIndex: "state",
    renderer:function(v,meta,record){
    	var value="",color="";
    	optStateStore.each(function(rd){
    		value=rd.get('value')==v?rd.get('name'):value;
    		color=rd.get('value')==v?rd.get('color'):color;
    	})
    	return "<font color='"+color+"'>"+value+"</font>";;
    },
  editor:new Ext.form.ComboBox({
		store:optStateStore,
		editable : false,
		mode:"local",
		triggerAction : 'all',
		displayField : 'name',
		valueField : 'value'
    })
},{
    header: "付款状态",
    align : 'center',
    width : 55,
    dataIndex: "payState",
    renderer:function(v,meta,record){
    	var value="",color="";
    	payStateStore.each(function(rd){
    		value=rd.get('value')==v?rd.get('name'):value;
    		color=rd.get('value')==v?rd.get('color'):color;
    	})
    	return "<font color='"+color+"'>"+value+"</font>";;
    },
  editor:new Ext.form.ComboBox({
		store:payStateStore,
		editable : false,
		mode:"local",
		triggerAction : 'all',
		displayField : 'name',
		valueField : 'value'
    })
},{
    header: "发货状态",
    align : 'center',
    width : 55,
    dataIndex: "deliverGoodsState",
    renderer:function(v,meta,record){
    	var value="",color="";
    	deliverGoodsStore.each(function(rd){
    		log.dir(rd);
    		value=rd.get('value')==v?rd.get('name'):value;
    		color=rd.get('value')==v?rd.get('color'):color;
    	})
    	return "<font color='"+color+"'>"+value+"</font>";;
    },
  editor:new Ext.form.ComboBox({
		store:deliverGoodsStore,
		editable : false,
		mode:"local",
		triggerAction : 'all',
		displayField : 'name',
		valueField : 'value'
    })
}];
	
	clientWin=new Ext.Window({
		title:'经销商订单详细',
		modal :'true',
		layout: 'border',
		width:835,
		height:450,
		autoDestroy:false,
		closable:false,
		resizable :true,
		buttons:[{
			text:'保存',
			handler:function(bt,e){
				var p=bt.ownerCt.ownerCt;
				var clientGrid_submitData=[];
				
				var clientStore = Ext.getCmp('clientOrderDetailGrid').getStore();
				clientStore.each(function(rd){
					clientGrid_submitData.push(rd.data)
				})
				
				var proxyManagerStore=Ext.getCmp('client_proxyManager_Grid').getStore();	
				proxyManagerStore.each(function(rd){
					clientGrid_submitData.push(rd.data)
				})
					var con = new connection({
						url : 'updateClientOrderDetailState.action',
						params : {
							cliOrdMasterId:Ext.getCmp("cliOrdMasterId_dl_fl").getValue(),
							json : Ext.encode(clientGrid_submitData)
						},
						success : function(rep, opt) {
							if (rep.success) {
								queryOrder();
								Ext.Msg.alert('恭喜',rep.msg);
							} else {
								Ext.Msg.alert('提示',rep.msg);
							}
						}
					})
					con.submit();
				p.hide();
			}
		},{
			text:'返回',
			handler:function(bt,e){
				var p=bt.ownerCt.ownerCt;
				p.hide();
			}
		}],
		showGridData : function (rep){
				var clientStore = Ext.getCmp('clientOrderDetailGrid').getStore();
				clientStore.removeAll();
				var proxyManagerStore=Ext.getCmp('client_proxyManager_Grid').getStore();
				proxyManagerStore.removeAll();
				Ext.each(rep.obj.clientOrderDetaillist, function(data) {
					var rd = Record_create_FromArray(data);
					if(Ext.isEmpty(rd.get('inlayDiamondId')) || rd.get('inlayDiamondId')<1){
						clientStore.add(rd);
					}else{
						proxyManagerStore.add(rd);
					}
				});
			},
	    items: [{
			region: 'north',
			split: true,
			border: false,
			height: 115,
			collapseMode: 'mini',
			layout: 'column',
			frame: true,
			defaults: {
				anchor: '95%',
				columnWidth: 0.32,
				layout: 'form',
				labelWidth: 60,
				defaults: {
					anchor: '95%',
					editable: false,
					xtype: 'textfield'
					}
				},
				items: [{
					columnWidth: 0.25,
					items: [{
						id:'cliOrdMasterId_dl_fl',
						name:'cliOrdMasterId',
						xtype:'hidden'
					},{
						fieldLabel: '订单类型',
						id: 'orderStatus_de_fl',
						disabled : true, 
						name : 'status',
						emptyText:'客户订单',
						style : 'color:#0000CC;font-weight:bold;'
//						xtype: 'combo'
					},{
						fieldLabel: '商家名称',
						disabled : true, 
						name : 'userName',
						id: 'userName_fl',
						style : 'color:#0000CC;font-weight:bold;'
					},{
						fieldLabel: '代理价格',
						disabled : true, 
						id: 'costTotal',
						name : 'costTotal',
						style : 'color:#0000CC;font-weight:bold;'
					},{
						fieldLabel: '经销价格',
						disabled : true, 
						id: 'midTotal',
						name : 'midTotal',
						style : 'color:#0000CC;font-weight:bold;'
					}]
				}, {
					items: [{
						fieldLabel: '订单编号',
						disabled : true, 
						name : 'orderNo',
						id: 'orderNo_dl_fl',
						style : 'color:#0000CC;font-weight:bold;'
					},{
						fieldLabel: '买家姓名',
						disabled : true, 
						name : 'buyerName',
						id: 'buyerName_dd_fl2',
						style : 'color:#0000CC;font-weight:bold;'
					},{
						fieldLabel: '下单时间',
						id: 'orderDate_de_fl2',
						name : 'orderDate',
						disabled : true,
						style : 'color:#0000CC;font-weight:bold;'
					}]
				}, {
					labelWidth: 80,
					items: [{
						fieldLabel: '单据状态',
						disabled : true, 
						name : 'orderStatusName',
						id: 'orderType_dd_fl',
						style : 'color:#0000CC;font-weight:bold;'
					},{
						fieldLabel: '买家联系方式',
						disabled : true, 
						id: 'buyer_tel_dcw_fl',
						name : 'buyerTel',
						xtype: 'textfield',
						style : 'color:#0000CC;font-weight:bold;'
					},{
						fieldLabel: '预计取货时间',
						disabled : true, 
						name : 'receiveDate',
						id: 'receiveDate_take_fl',
						style : 'color:#0000CC;font-weight:bold;'
					}]
				}, {
					columnWidth:'0.66',
					items: [{
						fieldLabel: '订单备注',
						disabled : true, 
						name : 'orderRemark',
						id: 'order_remark_memo',
						style : 'color:#FF0000;font-weight:bold;'
					}]
				}]
		},new Ext.grid.EditorGridPanel({
					autoDestroy:true,
	        		region: 'center',
	        		collapseMode: 'mini',
			        split: true,
			        border: false,
	        		clicksToEdit:1,
					store: new Ext.data.JsonStore({
						url:'',
						fields:getFieldsFromColumns(clientGridColumns)
					}),
			//		sm:suppGridColumns_sm,
					id : 'clientOrderDetailGrid',
					name : 'clientOrderDetailGrid',
					cm: new Ext.grid.ColumnModel({
						defaultSortable: true,
						defaultWidth: 85,
						columns:clientGridColumns
					}),
					frame: true
				}),new Ext.grid.EditorGridPanel({
					height:120,
					autoDestroy:true,
					id:'client_proxyManager_Grid',
					name : 'client_proxyManager_Grid',
			     	region: 'south',
			     	collapseMode: 'mini',
			        split: true,
			         border: false,
			        clicksToEdit:1,
			        store: new Ext.data.JsonStore({
						url:'',
						fields:getFieldsFromColumns(proxyManager_columns)
			        }),
					cm: new Ext.grid.ColumnModel({
						  defaultSortable: true,
						  defaultWidth: 70,
						  columns:proxyManager_columns
						})
			})]
	})
	clientWin.show();
	return clientWin;
}